var $ = require("jquery");
require("jquery.cookie");
var dict = require('../model/dict.js');
var view = require('../view/index.js');
var base = require("../base.js");

base.checklogin();


view.pageSelect.hide();

//
var initcourse = dict.courses(function render(list) {
	view.renderCourses(list);
	view.courses.on('click', 'a', function(event) {
		event.preventDefault();
		var course = $(this).attr("data");
		$.cookie("course", course);
		var cmd = parseInt($.cookie("cmd"));
		if (cmd < 4) {
			location.href = "question.html";
		}
		if (cmd == 4)
			location.href = "history.html";
	});
});


//选择功能
view.cmdlist.on('click', 'a', function(event) {
	event.preventDefault();
	var cmd = $(this).attr("data");
	$.cookie("cmd", cmd);
	if (parseInt(cmd) <= 4) {
		view.pageSelect.show();
		view.pageMain.hide();
	}
});

//回到首页
$('body').on('click', '.tohome', function(event) {
	event.preventDefault();
	view.pageMain.show();
	view.pageSelect.hide();
});